import {Component, OnInit} from '@angular/core';
import {BarnTeamService} from "../service/barn-team.service";
import {BarnTeam} from "../entity/barn-team";
import {FormControl, FormGroup} from "@angular/forms";

@Component({
  selector: 'app-team-info',
  templateUrl: './team-info.component.html',
  styleUrls: ['./team-info.component.less']
})
export class TeamInfoComponent implements OnInit{

  validateForm = new FormGroup({
    teamName: new FormControl(),
    enable: new FormControl('')
  })

  teams: BarnTeam[]
  current = 1;
  pageSize = 20;
  total = 1000;
  pageSizes = [this.pageSize, 50, 100]
  loading = false

  constructor(private teamService: BarnTeamService) {
  }

  ngOnInit(): void {
    this.search();
  }

  search() {
    this.loading = true
    const param = this.validateForm.getRawValue()
    this.teamService.query(param, this.current, this.pageSize)
      .subscribe(value => {
        this.loading = false
        this.teams = value.data
        this.current = value.current || 1
        this.total = value.count || 1
      }, () => this.loading = false)
  }

}
